Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pkg.BinaryPlatforms invalidations by moving module to Base #52249

Closed
wants to merge 10 commits into from

Conversation

mkitti
Copy link
Contributor

@mkitti mkitti commented Nov 21, 2023

  • Move Pkg.BinaryPlatforms compatibility shim to Base.BinaryPlatforms.PkgCompat
  • Move UnstableIO from Pkg.jl to Base

Address Pkg.jl invalidations by moving code to Base
JuliaLang/Pkg.jl#3702

Edits

@ViralBShah ViralBShah added the domain:packages Package management and loading label Nov 21, 2023
base/io.jl Outdated

Type unstable wrapper around an IO to avoid specializing write, get, and print
"""
struct UnstableIO <: IO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably beside the point, but this is insufficient to avoid inference inferring these functions on specialized IO. For that you'd need to add an extra inferencebarrier in the UnstableIO constructor.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked pretty well in practice. :p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Keno, would that look like the following?

struct UnstableIO <: IO
    io::IO
    UnstableIO(@nospecialize(x)) = new(inferencebarrier(x))
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Keno I added an inferencebarrier in 1f0876f

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct also doesn't seem compliant with the IO interface, so I am very reluctant to have this merged into Base. Perhaps make this <: AbstractPipe might suffice though, as then you get all of the required methods "for free"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an IO interface? Let me see if I can find it. I'm going to see if I can figure this out quickly. Otherwise, I will separate this into another pull request.

Copy link
Sponsor Member

@staticfloat staticfloat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were there no tests in Pkg for these that could be copied over as well?

base/binaryplatforms_pkgcompat.jl Outdated Show resolved Hide resolved
@mkitti
Copy link
Contributor Author

mkitti commented Dec 7, 2023

I can port over https://github.com/JuliaLang/Pkg.jl/blob/master/test/binaryplatforms.jl

@mkitti
Copy link
Contributor Author

mkitti commented Dec 8, 2023

I ported over the BinaryPlatforms tests in
9843555 .

I added Base.UnstableIO tests in 172909b

@mkitti
Copy link
Contributor Author

mkitti commented Dec 9, 2023

@vtjnash
I refactored UnstableIO onto AbstractPipe in b55dc3d

@mkitti
Copy link
Contributor Author

mkitti commented Dec 13, 2023

Is there anything else to do here? Should I split the PR into two parts?

base/io.jl Outdated
@@ -1520,3 +1520,17 @@ function countlines(io::IO; eol::AbstractChar='\n')
end

countlines(f::AbstractString; eol::AbstractChar = '\n') = open(io->countlines(io, eol = eol), f)::Int

# From Pkg.jl
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to make Pkg instead use an IOContext{IO}(io), since it has the same implementation as this, without needing to add code to Base just for Pkg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that, but IOContext has a type parameter indicating the parent type. I thought the objective was to create an abstract inference barrier so as to not force recompilation of Pkg methods for new IO types.

I'm thinking of splitting the pull request so that we can focus on this issue.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true of the usual interface, but it is valid for the parameter to be simply IO also. Someone could make a PR to make that constructor a bit simpler also, as right now it is potentially a bit awkwardly specified as IOContext{IO}(unwrapcontext(io)...) and does not reliably propagate when making a new IOContext from an existing one with more keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see so I may be able to define the following.

UnstableIO(io:IO) = IOContext{IO}(inferencebarrier(io))

@mkitti
Copy link
Contributor Author

mkitti commented Dec 13, 2023

Unless I hear otherwise, I intend to drop the UnstableIO part of the PR from this pull request.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Dec 13, 2023

Why do we need all the other stuff here too? It seems like if Pkg wants to export something with a similar name that does something different it should export something different, rather than pirating the method from Base or expecting Base to contain that functionality.

@mkitti
Copy link
Contributor Author

mkitti commented Dec 13, 2023

Right now I'm looking for pragmatic steps to take to improve load times of Pkg as an independent package. My overarching motivation is to reduce the negative impact on the user experience that breaking these packages out creates.

To be fair, it was Base that committed the piracy against Pkg. This was originally a Pkg API.

The code here is a compatability shim because the API changed when this functionality moved from Pkg to Base. Now that Pkg.jl is no longer part of the system image, we have invalidation issues due that prior solution. While one could debate this, we are obligated to carry that compatibility shim, I believe.

I'm going to invite @staticfloat and @giordano to comment on where the older BinaryPlatforms API is still used and why we need the compatibility shim.

@mkitti mkitti changed the title Fix Pkg.jl invalidations by moving code to Base Fix Pkg.BinaryPlatforms invalidations by moving module to Base Dec 18, 2023
@mkitti
Copy link
Contributor Author

mkitti commented Dec 18, 2023

I proposed an alternative approach is JuliaLang/Pkg.jl#3736 . That change is breaking in that it eliminates the ability to dispatch on the Linux, Windows, and MacOS types. Those are now constructors for Base.BinaryPlatforms.Platform. Surveying JuliaHub for use of the symbols, only a single registered package, AppBundler.jl, was found to be affected by the breakage so far.

@ararslan
Copy link
Member

FWIW the point of those types was to enable dispatch, which I've personally used extensively, just not in any registered packages.

@mkitti
Copy link
Contributor Author

mkitti commented Dec 22, 2023

I have proposed another alternative in JuliaLang/Pkg.jl#3742 , this time keeping the types. To avoid invalidations, I do not subtype Base.BinaryPlatforms.AbstractPlatform.

@mkitti mkitti closed this Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:packages Package management and loading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants